﻿using BusinessLogic.Services.Mapping;
using BusinessLogic.Services.Operations;
using BusinessLogic.Services.Security;
using BusinessLogic.Services.Validation;
using Interfaces.BusinessLogic;
using Interfaces.Models;
using Interfaces.RepositoryModels.InternalModels.UserRoleModels;
using Interfaces.Validation.Services;
using Microsoft.Practices.Prism.Modularity;
using Microsoft.Practices.Unity;
using ServiceInfrastructure.Models.NewsModels.Models;
using ServiceInfrastructure.Models.SecurityModels.Models;

namespace BusinessLogic.Services
{
    public class ServicesModule : IModule
    {
        private readonly IUnityContainer _container;

        public ServicesModule(IUnityContainer container)
        {
            _container = container;
        }

        public void Initialize()
        {
            #region services

            _container.RegisterType<IInternalSecurityService, InternalSecurityService>();
            _container.RegisterType<IUserOperationService, UserOperationService>();
            _container.RegisterType<IRoleOperationService, RoleOperationService>();
            _container.RegisterType<ISessionOperationService, SessionOperationService>();
            _container.RegisterType<IFeedOperationService, FeedOperationService>();

            #endregion

            #region Mappers

            _container.RegisterType<IEntityMapper<IUser, UserModel>, UserMapper>(new PerThreadLifetimeManager());
            _container.RegisterType<IEntityMapper<UserModel, IUser>, UserMapper>(new PerThreadLifetimeManager());
            _container.RegisterType<IEntityMapper<IFeed, Feed>, FeedContractMapper>(new PerThreadLifetimeManager());
            _container.RegisterType<IEntityMapper<IUser, User>, UserContractMapper>(new PerThreadLifetimeManager());
            _container.RegisterType<IEntityMapper<IRole, Role>, RoleContractMapper>(new PerThreadLifetimeManager());
            
            #endregion

            #region validation

            _container.RegisterType<IUserValidationService, UserValidationService>(new PerThreadLifetimeManager());
            _container.RegisterType<ISessionValidationService, SessionValidationService>(new PerThreadLifetimeManager());
            _container.RegisterType<INewsValidationService, NewsValidationService>(new PerThreadLifetimeManager());

            #endregion
        }
    }
}
